package com.gpy.hospital.cms.controller;

import com.github.pagehelper.PageInfo;
import com.gpy.hospital.cms.pojo.Blog;
import com.gpy.hospital.cms.pojo.Urgent;
import com.gpy.hospital.cms.service.IUrgentService;
import com.gpy.hospital.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author
 * @Date 2020/6/1 20:26
 * @Desc
 **/
@Controller
public class UrgentController {

    @Autowired
    private IUrgentService urgentService;


    @GetMapping("/reception/urgent")
    public String urgent(String phone, Model model){
        String code = urgentService.save(phone);
        model.addAttribute("code", code);
        return "/reception/urgentSuccess";
    }


    @GetMapping("/cms/urgent/page")
    public String urgentPage(){
        return "/cms/urgentList";
    }

    @GetMapping("/cms/urgent")
    @ResponseBody
    public ServerResponse blogPage(@RequestParam(value = "phone", required = false) String phone,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<Urgent> urgentPageInfo = urgentService.getAll(pageNum, pageSize, phone);
        return ServerResponse.createBySuccess("查询成功！", urgentPageInfo.getList(), urgentPageInfo.getTotal());
    }

    @GetMapping("/cms/urgent/edit")
    @ResponseBody
    public ServerResponse cmsEdit(Integer id) {
       return urgentService.update(id);
    }

}
